/******************************************************************************
 * * alarm_global.h - data structure for alarm module
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#ifndef ALARM_GLOBAL_H
#define ALARM_GLOBAL_H

#ifdef __cplusplus
extern "C" {
#endif

/* include header file */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ui_type.h"
#include "ui_textid.h"
#include "modem/mmi_modemadp_interface.h"
#include "ui_nvm_interface.h"
#include "inter_common_ui_interface.h"
#include "inter_framework_alarm_interface.h"
#include "inter_alarm_calendar_interface.h"
#include "inter_framework_interface.h"
#include "inter_setting_interface.h"
#include "nav.h"
#include "../../lvgl/hal/hal.h"
#include "utility.h"

#define ALARM_STATUS_TIMER_LEN     (2000)                   /* in ms */
#define ALARM_RING_TONE_COUNT      (6)
#define ALARM_RING_TIMER_LEN       (58 * 1000)              /* in ms */
#define ALARM_RING_REPEAT_INTERVAL (10)                     /* in minutes */
#define ALARM_MAX_SNOOZE_TIMES     (10)
#define ALARM_SECONDS_FOR_ONE_DAY  (3600 * 24)              /* in seconds */
#define ALARM_SECONDS_FOR_ONE_WEEK (3600 * 24 * 7)          /* in seconds */

/**********************
*      TYPEDEFS
**********************/
/* Alarm management */
typedef struct {
    NV_UI_Alarm_t              Alarm;                         /* alarm info */
    UINT8                      RingAlarmId;                   /* the ringing alarm id */
    UINT8                      RtcAlarmId;                    /* bitmap for alarm ids which has been set to rtc */
    UINT8                      CurrAlarmId;                   /* current alarm ID: 0 or 1*/
    UINT8                      RepeatBitmapTemp;              /* temp repeat bitmap,
                                                               * Bit 7: 0 means alarm once, 1 means repeat alarm,
                                                               * Bit 0 ~ 6 are valid if bit 7 is 1,
                                                               * Bit 0: Sunday, bit 1: Monday ... bit 6: Saturday */
    VOID                       *CurrDesc;                     /* desc of current UI */
    TIMER_ID                   Timer;
    TIMER_ID                   StatusTimer;
    ACTIVITY_ID                SrcActId;
} Alarm_Mng_t;

/**********************
* GLOBAL VARIABLES
**********************/
extern const INT8  *g_Alarm_Ringing_Tone[ALARM_RING_TONE_COUNT];
extern Alarm_Mng_t g_Alarm_Mng;

/**********************
* GLOBAL PROTOTYPES
**********************/
/*------ alarm_main ------*/
VOID Alarm_Main(VOID);
VOID Alarm_Ring_Stop_Handle(BOOL Delay);
VOID Alarm_Ringing_Cb(VOID);
VOID Alarm_Set_Recent_Alarm(BOOL AlarmChg, BOOL ZeroSec);

/*------ alarm_ui ------*/
extern VOID Display_Alarm(VOID);
extern VOID Display_Alarm_Set(VOID);
extern VOID Display_Alarm_Set_Time(BOOL New);
extern VOID Display_Alarm_Edit(VOID);
extern VOID Display_Alarm_Repeat(VOID);
extern VOID Display_Alarm_Tone(VOID);
extern VOID Display_Alarm_Ringing_Tone(VOID);
extern VOID Display_Alarm_Ring(UINT8 AlarmId);
extern VOID Display_Alarm_Status(ACTIVITY_ID ActId);

/*------ alarm_proc ------*/
// Alarm
extern VOID Alarm_Proc_Btn_Set_Alarm(lv_obj_t *Btn, lv_event_t e);
extern VOID Alarm_Proc_Btn_Alarm_Tone(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Set
extern VOID Alarm_Proc_Btn_Alarm1(lv_obj_t *Btn, lv_event_t e);
extern VOID Alarm_Proc_Btn_Alarm2(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm_Set(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Set Time
extern UINT8 Alarm_Proc_Key_Alarm_Set_Time(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Edit
extern VOID Alarm_Proc_Btn_Adjust(lv_obj_t *Btn, lv_event_t e);
extern VOID Alarm_Proc_Btn_Off(lv_obj_t *Btn, lv_event_t e);
extern VOID Alarm_Proc_Btn_Repeat(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm_Edit(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Repeat
extern VOID Alarm_Proc_Btn_Mode_Once(lv_obj_t *Btn, lv_event_t e);
extern VOID Alarm_Proc_Btn_Mode_Repeat(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm_Repeat(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Repeat Select
extern VOID Alarm_Proc_Btn_Repeat_Select_Wday(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm_Repeat_Select(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);
extern VOID Display_Alarm_Repeat_Select(VOID);

// Alarm Tone
extern VOID Alarm_Proc_Btn_Standard(lv_obj_t *Btn, lv_event_t e);
extern VOID Alarm_Proc_Btn_Ringing_Tone(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm_Tone(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Ringing Tone
extern VOID Alarm_Proc_Btn_Ringing_Tone_Select(lv_obj_t *Btn, lv_event_t e);
extern UINT8 Alarm_Proc_Key_Alarm_Ringing_Tone(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Ring
extern UINT8 Alarm_Proc_Key_Alarm_Ring(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);

// Alarm Status Timeout
extern VOID Alarm_Proc_Status_Timeout(VOID* Para);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* ALARM_GLOBAL_H */
